package com.jf3q.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.common.domain.EduMember;
import com.jf3q.common.domain.EduOrder;
import com.jf3q.common.mapper.EduMemberMapper;
import com.jf3q.common.mapper.EduOrderMapper;
import com.jf3q.common.utils.SaltPassUtils;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<EduOrderMapper, EduOrder> implements OrderService {

    @Resource
    private EduMemberMapper eduMemberMapper;

    @Resource
    EduOrderMapper eduOrderMapper;

    @Override
    public ResultVo checkOldPwd(String password, String phone) {
        QueryWrapper<EduMember> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(phone != null && !"".equals(phone), EduMember::getMobile, phone);
        EduMember member = eduMemberMapper.selectOne(queryWrapper);
        if (member == null) {
            return ResultVo.error("没有该用户");
        }
        Boolean flag = SaltPassUtils.PasswordValidation(member.getSalt(), password, member.getPassword());
        if (flag) {
            return ResultVo.success("密码校验成功");
        }
        return ResultVo.error("密码校验失败");
    }

    @Override
    public ResultVo orSave(String mobile) {
        return eduOrderMapper.orSave(mobile);
    }
}
